package com.weihuachao.repair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Virgo on 2016/7/30.
 */
public class ProfileActivity extends Activity {
    private TextView weidenglu;
    private ImageView touxiang;
    private View addo;
    private View login_pro;
    private View mainbutton;
    private View mywork;
    private View repassword;
    private View submit;
    String string;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pro);
        string = com.weihuachao.app.application.getAccount();
        weidenglu = (TextView) findViewById(R.id.dengluxinxi);
        mainbutton = findViewById(R.id.mainButton);
        addo = findViewById(R.id.addwork);
        login_pro = findViewById(R.id.login_profile);
        mywork = findViewById(R.id.mywork_profile);
        repassword = findViewById(R.id.repassword_profile);
        submit = findViewById(R.id.feebback_profile);

        if (string != null) {
            weidenglu.setText(string);
            touxiang = (ImageView) findViewById(R.id.touxiang);
            touxiang.setImageDrawable(getResources().getDrawable(R.drawable.logined));
        } else {
            weidenglu.setText("未登录");
            touxiang = (ImageView) findViewById(R.id.touxiang);
            touxiang.setImageDrawable(getResources().getDrawable(R.drawable.unlogin));
        }

        mywork.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (checkLogined()) {
                    startActivity(new Intent(ProfileActivity.this, MyWorkActivity.class));
                }
                return false;
            }
        });
        mainbutton.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                startActivity(new Intent(ProfileActivity.this, MainActivity.class));
                return false;
            }
        });
        login_pro.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (string == null) {
                    startActivity(new Intent(ProfileActivity.this, LoginActivity.class));
                }
                return false;
            }
        });
        addo.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (checkLogined()) {
                    startActivity(new Intent(ProfileActivity.this, AddWorkActivity.class));
                }
                return false;
            }
        });
        repassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (checkLogined()) {
                    startActivity(new Intent(ProfileActivity.this, RepasswordActivity.class));
                }
            }
        });
        submit.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (checkLogined()) {
                    startActivity(new Intent(ProfileActivity.this, FeedbackActivity.class));
                }
                return false;
            }
        });
    }

    //已登录返回true
    private boolean checkLogined() {
        if (weidenglu.getText().toString().equals("未登录")) {
            Toast.makeText(ProfileActivity.this, "请先登录！", Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (com.weihuachao.app.application.getAccount() == null) {
            string=null;
            weidenglu.setText("未登录");
            touxiang = (ImageView) findViewById(R.id.touxiang);
            touxiang.setImageDrawable(getResources().getDrawable(R.drawable.unlogin));
        }
    }
}
